<template>
    <view style="display: flex; flex-direction: column; height: 100vh">
		<xmInfo
		    :projectno="itemContent.projectno"
		    :projectname="itemContent.projectname"
		  ></xmInfo>
		  <scroll-view class="scroll-list" scroll-y="true" @scrolltolower="loadMore" :refresher-enabled="true"
		  	:refresher-triggered="triggered" @refresherrefresh="refresherrefresh">
        <view >
            <!-- @click="add(item)" -->
            <view class="cu-item shadow" v-for="(item,index) in list" :key="item.id">
				<view
				    class="cu-form-group"
				    style="display: flex; justify-content: space-between"
				  >
				    <view
				      style="
				        display: inline-block;
				        padding: 5px;
				        background: #3e97b0;
				        color: #fff;
				        width: 40px;
				        text-align: center;
				        font-style: italic;
				        font-weight: bold;
				      "
				    >
				      {{ index + 1 }}
				    </view>
					
					<dictLabel
					:value="item.checkResult ? item.checkResult : ''"
					  dict-type="zf_check_result"
					  :dict-list="dictList2"
					  :fontSize="'30rpx'"
					></dictLabel>
				   
					<dictLabel
					  :value="item.status ? item.status : 0"
					  dict-type="bpm_biz_status"
					  :dict-list="dictList"
					  :fontSize="'30rpx'"
					></dictLabel>
				  </view>
				  
				 <!-- <view class="cu-form-group">
				    <view style=" display: inline-block;padding: 5px;background: #0081ff;color: #fff;text-align: center;font-style: italic;font-weight: bold">
				        申请信息
				      </view>
				  </view> -->
				  <view class="cu-card">
                <view class="cu-form-group" >
                    <view class="title">发起信息</view>
                    <view >{{ item.createDate }} {{ item.createByName }}</view>
                </view>
                <!-- <view class="cu-form-group">
                    <view class="title">接水类别</view>
                    <view>{{ item.jieshui_type === 1 ? '临时计划' : '年度计划' }}</view>
                </view> -->
               <!-- <view class="cu-form-group">
                    <view class="title">工程编码</view>
                    <view>{{ item.projectno }}</view>
                </view>
              
                <view class="cu-form-group">
                    <view class="title">工程名称</view>
                    <view>{{ item.projectname }}</view>
                </view> -->
                <view class="cu-form-group">
                    <view class="title">开工时间</view>
                    <view>{{ item.projInfo.pmStatus.enDate }}</view>
                </view>
                <view class="cu-form-group">
                    <view class="title">项目地址</view>
                    <view>{{ item.projInfo.projectaddress }}</view>
                </view>
                <view class="cu-form-group">
                    <view class="title">施工员</view>
                    <view>{{ item.projInfo.pmZone.contacts }}</view>
                </view>
				<view class="cu-form-group">
				    <view class="title">承包商</view>
				    <view>{{ item.projInfo.pmZone.pmContractor.name }}</view>
				</view>
				<!-- <view class="cu-form-group">
				    <view class="title">发起人</view>
				    <view>{{ item.createByName }}</view>
				</view> -->
				<view class="cu-form-group">
				    <view class="title">发起备注</view>
				    <view>{{ item.remarks }}</view>
				</view>
				
				<view class="cu-form-group" style="min-height: 0"></view>
				<view class="cu-bar bg-white">
				  <view class="action text-black">发起图片</view>
				</view>
				<view class="cu-form-group">
				  <js-uploadfile  v-model="item.dataMap"   :biz-key="item.id"   biz-type="PmAcceptance_create_image" :showProgress="false" :deletable="false" customBtn="false"></js-uploadfile>
				</view>
				
				<view class="cu-form-group" style="min-height: 0"></view>
				<view class="cu-bar bg-white">
				  <view class="action text-black">中间验收表</view>
				</view>
				<view class="cu-form-group">
				  <js-uploadfile  v-model="item.dataMap" uploadType="all"  uploadText="请上传文件"  :biz-key="item.id"   biz-type="PmAcceptance_midYs_file" :showProgress="false" :deletable="false" customBtn="false"></js-uploadfile>
				</view>
				</view>
				
				<view class="cu-form-group">
				  <view style=" display: inline-block;padding: 5px;background: #0081ff;color: #fff;text-align: center;font-style: italic;font-weight: bold">
				      验收结果
				    </view>
				</view>
				<view class="cu-card">
					<view class="cu-form-group">
					    <view class="title">验收信息</view>
					    <view>{{ item.launchtime || '' }} {{ item.pername || ''}}</view>
					</view>
				<view class="cu-form-group">
				    <view class="title">验收结果</view>
				    <view>{{ item.checkResult }}</view>
				</view>
				<!-- <view class="cu-form-group">
				    <view class="title">验收日期</view>
				    <view>{{ item.launchtime }}</view>
				</view> -->
				
				
				<!-- <view class="cu-form-group">
				    <view class="title">验收人名称</view>
				    <view>{{ item.pername }}</view>
				</view> -->
				<view class="cu-form-group">
				    <view class="title">不合格描述</view>
				    <view>{{ item.unqualified }}</view>
				</view>
				
				
				<view class="cu-form-group" style="min-height: 0"></view>
				<view class="cu-bar bg-white">
				  <view class="action text-black">验收图片</view>
				</view>
				<view class="cu-form-group">
				  <js-uploadfile  v-model="item.dataMap"   :biz-key="item.id"   biz-type="PmAcceptance_result_image" :showProgress="false" :deletable="false" customBtn="false"></js-uploadfile>
				</view>
				</view>
				
				
				<!-- <view class="dictLabel">
				  <dictLabel
				    :value="item.status ? item.status : 0"
				    dict-type="bpm_biz_status"
				    :dict-list="dictList"
				    :fontSize="'30rpx'"
				  ></dictLabel>
				</view> -->
               
                <!-- <view class="cu-form-group" style="min-height: 0;"></view> -->
                <!-- <view class="cu-bar bg-white">
                    <view class="action text-black">接水现场图片</view>
                </view>
                <view class="cu-form-group">
                    <view class="grid col-4 grid-square flex-sub">
                        <view class="bg-img" v-for="(itemImg,index) in item.jieshui_img" :key="itemImg" @tap.stop="ViewImage(item.jieshui_img,$event)" :data-url="item.jieshui_img[index]">
                        <image :src="item.jieshui_img[index]" mode="aspectFill"></image>
                            <view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
                            </view>
                        </view>
                    </view>

                </view> -->     
            </view>
        </view>
		<view v-if="list.length" class="loadmore">
			<u-loadmore :status="loadStatus"></u-loadmore>
		</view>
		<u-empty v-if="!list.length"></u-empty>
		</scroll-view>
	</view>
</template>
<script>
import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import dictLabel from "@/pages/zfgs/index/componetns/dictLabel.vue";
  export default{
  components: { xmInfo,dictLabel },
    data(){
        return{
			triggered: false,
			loadStatus: 'loadmore',
			query: {
				pageNo: 1,
				pageSize: 20,
			},
			itemContent:{},
            imgList: ["http://192.168.1.49:8080/app/static/image/zfgs/zfgs1.jpg","http://192.168.1.49:8080/app/static/image/zfgs/zfgs2.jpg"],
            list:[
            ],
            modalNameDetail:null,
            applyFile:[],
            showAddDetail:false,
			dictList: [],
			dictList2: [],
        }
    },
	onShow() {
		this.query.pageNo = 1;
		this.loadList();
	},
	onLoad(e) {
		this.getDictList()
	  if (typeof e.item !== "undefined") {
	    try {
	      this.itemContent = JSON.parse(e.item);
		 this.query.projectno = this.itemContent.projectno
	      console.log(this.itemContent);
	    } catch (error) {
	      console.error("Failed to parse item:", error);
	    }
	  } else {
	    console.warn("Item is undefined.");
	  }
	},
    methods:{
		getDictList() {
		  this.$u.api
		    .dictListData({ dictType: "bpm_biz_status" })
		    .then((res) => {
		      this.dictList = res;
		    });
			
			this.$u.api
			  .dictListData({ dictType: "zf_check_result" })
			  .then((res) => {
				this.dictList2 = res;
			  });
			
			
		},
        add(item){
			
			
            if(item){
                uni.navigateTo({
                    url: '/pages/zfgs/process/job/pmConnectwaterjob/resultForm?id='+item.id
				})
            }else{
                uni.navigateTo({
                    url: '/pages/zfgs/process/job/pmConnectwaterjob/createForm?projectno='+this.itemContent.projectno+ '&projectname='+this.itemContent.projectname
                })
            }
        },
        ViewImage(imageList,e) {
            // 阻止冒泡
            e.stopPropagation();
            uni.previewImage({
                urls: imageList,
                current: e.currentTarget.dataset.url
            });
        },
        async openDocument(attachment) {
      // 在App端使用uni-app原生API
            if (process.env.UNI_PLATFORM === 'app-plus') {
                const filePath = await this.downloadAndSaveAttachment(attachment.url);
                console.log('filePath', filePath);
                uni.openDocument({
                filePath: filePath,
                fileType: attachment.type,
                success: () => {},
                fail: () => {}
                });
            } else { // 在Web或小程序中，可能需要提供下载链接
                window.location.href = attachment.url;
            }
        },
        async downloadAndSaveAttachment(url) {
            // 这里是一个简化的下载并保存到本地临时文件的逻辑，实际开发中需要更完整的处理流程
            const {tempFilePath} = await uni.downloadFile({url});
            return tempFilePath;
        },
        addDetail(applyFile){
            this.showAddDetail = true;
            this.modalNameDetail = 'bottomModal'
            this.applyFile = applyFile
            console.log(applyFile,'applyFile',this.applyFile)


        },
        modalNameDetailEmit(e){
            this.modalNameDetail = e
            this.showAddDetail = false;
            
        },
		async refresherrefresh() {
			console.log(22222);
			this.triggered = true
			this.query.pageNo = 1;
			await this.loadList()
			this.triggered = false
		},
		loadList(type) {
			this.$u.api.zfgs.pmAcceptanceListData(this.query).then(res => {
				if (res.list.length < 20 || res.list.length == 0) {
					this.loadStatus = "nomore";
				}
				var list = res.list;
				if (type == "add") {
					for (var i = 0; i < list.length; i++) {
						this.list.push(list[i])
					}
				} else {
					this.list = list;
				}
			})
		
		},
		loadMore() {
			this.loadStatus = "loading";
			setTimeout(() => {
				this.query.pageNo += 1;
				this.loadList("add");
			}, 100);
		},
        
    }
  }

</script>
<style lang="scss" scoped>
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot{
    background: #fff;
    min-height: 80px;
}
.cu-item{
  flex-wrap: wrap;
  padding: 15px !important;
  position: relative;
  overflow: visible;
}
.title{
    flex-shrink: 0;
}
.grid-square{
    margin-bottom: 0 !important;
}
.cuIcon-image{
    width: 40px;
    height: 40px;
}
.dictLabel{
    position: absolute;
    top: -10px;
    right: -10px;
}
.cu-card{
  border: 1px solid #0081ff;
}
</style>